
// const baseUrl = 'http://123.249.97.22'//打包http://122.9.135.163:6084/
// const baseUrl = 'http://172.16.18.167:8080/'//文号
const baseUrl = 'https://lsydsq.cqlandcloud.org.cn'
const devbaseUrl = 'http://172.16.18.123:8037'
const request = {
	getBaseUrl(){
		if (process.env.NODE_ENV === 'development') {
			return baseUrl
		} else {
			return baseUrl
		}
	},
	get(url,params){
		return this.initRequest(url,params,'GET')
	},
	post(url,params){
		return this.initRequest(url,params,'POST')
	},
	postFormData(url,params){
		return this.initRequest(url,params,'POST','multipart/form-data')
	},
	
	initRequest(url,params,method='GET',contentType='application/json'){
		let userId = uni.getStorageSync('userId')
		let token = uni.getStorageSync('appToken')
		return new Promise((resolve, reject)=>{
			uni.request({
				url:`${this.getBaseUrl()}${url}`,
				data:params,
				method:method,
				header:{
					'userId':userId||'',
					'content-type':contentType,
					'accesstoken':token || '',
					'appflag':'0'
				}
			}).then(res=>{
				var [err, ret] = res;
				ret = !err ? (ret.data ? ret.data : ret) : {};
				if (ret.state == 200) {
					resolve(ret.data);
				} else{
					reject(ret.message)
				}
			}).catch(err=>{
				reject(err)
			})
		})
	}
	
}

export default request




